<?php session_start(); 
ob_start();
?>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
        </style>
        <link href="public/css/cssindex3.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <div id="full">
            <?php            include './class/header.php'; ?>
            
            
                     <div class="taskbar">   
                    <?php
                        if (!isset($_SESSION['id'])) {
                            require_once 'login.php';
                        } else {
                            require_once 'login.php';
                        }
                        ?>
                        <?php
                        if (isset($_GET["logout"]) && $_GET["logout"] == true) {
                            unset($_SESSION["id"]);
                            header("location:index3.php");
                        }
                        ?>
                         
                         
                         <?php if (isset($_SESSION['id']) == NULL) { ?>
            <img src="public/image/beated.png" width="90px" height="90px" style="margin-left: 700px; margin-top: -120px">
        
    <?php } else { ?>
        <?php if (isset($_SESSION['id']) && $_SESSION['id'] == 0): { ?>
                <h2 style="color: #ffffff;" align="center" style="margin-left: 400px; margin-top: -30px">Xin chào Admin</h2>
                <img src="public/image/boss.png" width="90px" height="90px" style="margin-left: 450px; margin-top: -15px">
            <?php }else: { ?>
                <h4 style="color: #ffffff;" align="center">Xin chào Ninpo</h4>
                <img src="public/image/byebye.png" width="90px" height="90px" style="margin-left: 450px; margin-top: -15px">
                   
            <?php }endif;
    }
    ?>
                    </div>
            
            <div id="noidung">
                
                

                <div class="cot2">
                    
                    
                    <?php
                    require_once './model/dbdemo.php';
                    require_once './model/wo.php';
                    require_once './model/paginationdemo.php';
                    
//        require_once './model/keywords.php';
//        $keys = new Keywords();
//        $key = $keys->maxlength();
                    $works = new Works();
                    $paginations = new Pagination();
                    ?>      
                    <?php
                    if (!isset($_GET["page"]))
                        $page = 1;
                    else
                        $page = $_GET["page"];
                    $list = $works->select_index($page);
                    $total = $works->countWords();
                    echo $paginations->Display($page, $total, null, "index3.php");
                    ?>
                    <br>                   
                    <table border="1px" align="center">
                        <tr class="works">
                            <?php if (isset($_SESSION['id']) == NULL) { ?>
                            <td><b>STT</b></td>
                            <td><b>name</b></td>
                            <td><b>description</b></td>
                            <td><b>posted</b></td>
                            
                            <?php } else { ?>
                            <td><b>STT</b></td>
                            <td><b>name</b></td>
                            <td><b>description</b></td>
                            <td><b>Image</b></td>
                            <td><b>posted</b></td>
                            
                            <?php
                                    if (!isset($_SESSION['id']) == 0) :
                                        ?>
                            <td><b>Edit</b></td>
                                    <?php else : ?>
                                        <td><b>Edit</b></td>
                                    <?php
                                    endif;
                                }
                                ?>
                            
                            
                        </tr>
                        <?php if (isset($_SESSION['id'])==NULL) { ?>
                        <?php foreach ($list as $item): ?>
                            <tr>
                                <td class="echo"><?php echo$item['id']; ?></td>
                                <td class="bgtable"><a href="<?php echo$item['url']; ?>" style="text-decoration: none">
                                        <?php echo$item['name']; ?></a></td>                                            
                                <td class="bgtable"><?php echo substr($item['description'], 0, 100); ?></td>
                                <td class="echo"><?php $mydate = getdate($item['posted']); ?> 
                                    <?php echo "$mydate[mday] $mydate[month], $mydate[year]"; ?></td>
                                 <?php endforeach; ?>
                                <?php }else { ?>
                                <?php if (isset($_SESSION['id'])) { ?>
                                        <?php foreach ($list as $item): ?>
                            <tr>
                                <td class="echo"><?php echo$item['id']; ?></td>
                                            <td class="bgtable1"><a href="<?php echo$item['url']; ?>" style="text-decoration: none">
                                                    <?php echo$item['name']; ?></a></td>                                            
                                            <td class="bgtable2"><?php echo substr($item['description'], 0, 100); ?></td>
                                            <td class="echo"><img src='<?php echo $item['image'] ?>' width="40px" height="40px"></td>
                                            <td class="echo"><?php $mydate = getdate($item['posted']); ?> 
                                                <?php echo "$mydate[mday] $mydate[month], $mydate[year]"; ?></td>
                                <?php
                                            if (isset($_SESSION['id']) && $_SESSION['id'] == 0) :
                                                ?>            
                                            
                                <td class="echo"> <a href="upload.php?id=<?php echo $item['id']; ?>">Edit</a>
                                    <a href="delete.php?id="<?php $item['id']; ?>>Delete</a><br>
                                    <a href="view.php?id=<?php echo $item['id']; ?>">View</a><br>
                                    <td class="echo"><img src="<?php echo$item['image'] ?>" with="50px" height="50px"</td><br>
                                    
   
                                </td>
                                <?php else : ?>
                                
                            <td class="echo"><a href="view.php?id=<?php echo $item['id']; ?>">View</a><br></td>
                            <td class="echo"><img src="<?php echo$item['image'] ?>" with="50px" height="50px"</td><br>
                                        <?php
                                    endif;
                                    ?>
                                </tr>
                            <?php endforeach; ?>
                                <?php
                        }
                        else
                            header("location:index3.php");
                                }
                        ?>
                       
                    </table>
                    <br>
                    <?php echo $paginations->Display($page, $total, null, "index3.php"); ?>
                    <br>

                </div>



            </div>
           

            <div id="fotter">@2014 Design by Team 1<br />
                C12TDC. Cao đẳng công nghệ Thủ Đức</div>
        </div>
        <?php
        // put your code here
        ?>
    </body>
</html>
<?php ob_end_flush(); ?>
